#ifndef SDLTEXTBOX_H
#define SDLTEXTBOX_H
#include <SDL.h>
#include <SDL_ttf.h>
#include <string>
#include <vector>
#include <utility>
#include "SDLutil.h"
#include "SDLObject.h"
#include "SDLMakeCursor.h"
#include "SDLClipboard.h"
#include "SDLPopupMenu.h"
#include "LOK2WindowManager.h"
#include "defines.h"
#include "structs.h"

class SDLPopupMenu;	//wtf?  If someone knows why I have to forward declare this, please tell me
class SDLObject;
class LOK2WindowManager;

using namespace std;

class SDLTextBox : public SDLObject {
	public:
		SDLTextBox();
		SDLTextBox(SDL_Surface *_screen, TTF_Font *_font, SDL_Color _textColor, SDL_Event *_event, SDLClipboard *_pClipboard, const char *bgFileName = 0, int _max_len = 256);
		~SDLTextBox();

		virtual void inputHandler();
		virtual void display();
		Uint32 toggleCaret(Uint32 interval, void *param);
		virtual int makeLines(int width);
		virtual int findCharXY(int x, int y);
		virtual void doHighlight();
		void setFocus(bool);
		bool hasFocus();
		bool popupActive();
		virtual SDL_Rect getRect() = 0;
		void setManager(LOK2WindowManager *manager);
	protected:
		void popupMenuAction(int num);
		friend SDLPopupMenu;
		LOK2WindowManager *pManager;
		SDL_Surface *screen, *textBoxBody;
		SDL_Color textColor;
		SDL_Event *event;
		TTF_Font *font;
		SDL_TimerID caretTimer;
		SDL_Cursor *textCursor;
		SDL_Cursor *normalCursor;
		SDLClipboard *pClipboard;
		SDLPopupMenu *pPopupMenu;
		bool m_hasFocus;
		int max_len, lines;
		vector <string> vLines;
		string str;
		struct {
			int x, y;
		} mousePos;
		struct {
			bool caretOn;
			bool caretOff;
			int caretLoc;
			int caretX;
			int caretY;
			int caretH;
			int debugX;
			int debugY;
		} caret;
		SDL_Rect box;
		struct {
			int start;
			int stop;
			bool active;
		} highlight;
};


Uint32 _toggleCaret(Uint32 interval, void *oTextBox);

#endif